package fu.capstone.hanoicityguide.dataaccess.cyclo;

import java.util.ArrayList;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import fu.capstone.hanoicityguide.business.model.Cyclo;
import fu.capstone.hanoicityguide.dataaccess.base.BaseDAOImpl;
import fu.capstone.hanoicityguide.dataaccess.base.DatabaseHelper;

public class CycloDAOImp extends BaseDAOImpl implements CycloDAO{

	private SQLiteDatabase database;
	private DatabaseHelper dbHelper;
	private Context context;
	
	public CycloDAOImp(Context ctx) {
		super(ctx);
		// TODO Auto-generated constructor stub
	}

	@Override
	public ArrayList<Cyclo> listCyclo(String filter, String sorter) {
		// TODO Auto-generated method stub
		Cursor cursor = null;
		ArrayList<Cyclo> arrResult = new ArrayList<Cyclo>();
		
		try {
			dbHelper = connectDB();
			database = dbHelper.getReadableDatabase();
			String queryCyclo = "SELECT * FROM Transport " +
					"LEFT JOIN TransportCategory ON Transport.[TransportID] = TransportCategory.[Id]  " +
					"WHERE TransportCategory.[TransportName] == \"Cyclo\"";

			cursor = database.rawQuery(queryCyclo, null);
			if (cursor != null) {
				if (cursor.moveToFirst()) {
					do {

						Cyclo cyclo = new Cyclo();
						cyclo.setId(cursor.getInt(cursor
								.getColumnIndex("Id")));
						cyclo.setName(cursor.getString(cursor
								.getColumnIndex("Name")));
						cyclo.setWebsite(cursor.getString(cursor
								.getColumnIndex("Website")));
						cyclo.setPhoneNumber(cursor.getString(cursor
								.getColumnIndex("PhoneNumber")));
						cyclo.setIconPath(cursor.getString(cursor
								.getColumnIndex("IconPath")));

						arrResult.add(cyclo);
					} while (cursor.moveToNext());
				}
			}
		} catch (Exception e) {
			Log.v("Can't query DB", e.toString());
		} finally {
			closeDB(database, dbHelper);
		}
		
		return arrResult;
	}

	@Override
	public ArrayList<Cyclo> searchCyclo(String filter, String sorter,
			String keyWord) {
		// TODO Auto-generated method stub
		return null;
	}
}
